package com.blog.aop;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

//此类未启用
public class ErrorAOP extends HandlerInterceptorAdapter {
    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
            // 请求处理完成之后
            super.afterCompletion(request, response, handler, ex);
    }

    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
            // 处理器执行完毕之后
             /*  
    		System.out.println("处理器执行完毕啦！");
            System.out.println(response.getStatus());
            
            if(response.getStatus()==404){ 
            	modelAndView.addObject("errorcode",404);
                modelAndView.setViewName("error");  
            }else if(response.getStatus()==500){  
            	modelAndView.addObject("errorcode",500);
                modelAndView.setViewName("error");  
            }  
                */
            super.postHandle(request, response, handler, modelAndView);
    }

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
            // 处理器实际执行之前
            //System.out.println("处理器执行之前！");
            return super.preHandle(request, response, handler);
    }
}